package com.javabrains.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;

import com.javabrains.dto.UserDetails;

public class HibernateTest {

	/*
	 * @param args
	 */
	public static void main(String[] args) {
		SessionFactory sessionFactory = new Configuration().configure()
				.buildSessionFactory();
		Session session = sessionFactory.openSession();
		session.beginTransaction();

		Criteria criteria = session.createCriteria(UserDetails.class);
		criteria.add(Restrictions.eq("userName", "user 5"));

		List<UserDetails> user = (List<UserDetails>) criteria.list();
		// session.getTransaction().commit();
		session.close();
		for (UserDetails u : user) {
			System.out.println("Name " + u.getUserName());
		}

	}
}
